/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.coo_education.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.coo_education.entity.TbCooEducation;
import com.thinkgem.jeesite.modules.coo_education.service.TbCooEducationService;

/**
 * 中外合作办学Controller
 * @author hang
 * @version 2017-01-15
 */
@Controller
@RequestMapping(value = "${adminPath}/coo_education/tbCooEducation")
public class TbCooEducationController extends BaseController {

	@Autowired
	private TbCooEducationService tbCooEducationService;
	
	@ModelAttribute
	public TbCooEducation get(@RequestParam(required=false) String id) {
		TbCooEducation entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbCooEducationService.get(id);
		}
		if (entity == null){
			entity = new TbCooEducation();
		}
		return entity;
	}
	
	@RequiresPermissions("coo_education:tbCooEducation:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbCooEducation tbCooEducation, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbCooEducation> page = tbCooEducationService.findPage(new Page<TbCooEducation>(request, response), tbCooEducation); 
		model.addAttribute("page", page);
		return "modules/coo_education/tbCooEducationList";
	}

	@RequiresPermissions("coo_education:tbCooEducation:view")
	@RequestMapping(value = "form")
	public String form(TbCooEducation tbCooEducation, Model model) {
		model.addAttribute("tbCooEducation", tbCooEducation);
		return "modules/coo_education/tbCooEducationForm";
	}

	@RequiresPermissions("coo_education:tbCooEducation:edit")
	@RequestMapping(value = "save")
	public String save(TbCooEducation tbCooEducation, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbCooEducation)){
			return form(tbCooEducation, model);
		}
		tbCooEducationService.save(tbCooEducation);
		addMessage(redirectAttributes, "保存中外合作办学成功");
		return "redirect:"+Global.getAdminPath()+"/coo_education/tbCooEducation/?repage";
	}
	
	@RequiresPermissions("coo_education:tbCooEducation:edit")
	@RequestMapping(value = "delete")
	public String delete(TbCooEducation tbCooEducation, RedirectAttributes redirectAttributes) {
		tbCooEducationService.delete(tbCooEducation);
		addMessage(redirectAttributes, "删除中外合作办学成功");
		return "redirect:"+Global.getAdminPath()+"/coo_education/tbCooEducation/?repage";
	}

}